Skip to content

Handle JsonSchemaRequestException as 400 Bad Request in ThrowableHandler - #189

Merged
koriym merged 3 commits into
1.xfrom
feature/json-schema-exception-handler
Aug 23, 2026
Merged

Handle JsonSchemaRequestException as 400 Bad Request in ThrowableHandler#189
koriym merged 3 commits into
1.xfrom
feature/json-schema-exception-handler

Conversation

@koriym

@koriym koriym commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Raise bear/resource requirement from ^1.16 to ^1.33
  • In ThrowableHandler::handle(), convert JsonSchemaRequestException to BadRequestException, preserving its 4xx code, so VndError emits the correct 4xx response instead of the generic 500
  • JsonSchemaResponseException (server-side schema mismatch) continues to produce a 500 — no change needed
  • Tests added for both exception types

Test plan

  • testJsonSchemaRequestException → 400 with application/vnd.error+json
  • testJsonSchemaRequestExceptionWithCustomCode → preserves a non-default 4xx code (403) with application/vnd.error+json
  • testJsonSchemaResponseException → 500 with application/vnd.error+json
  • Existing testException (404) and testError (PHP Error → 500) still pass

Raise the minimum bear/resource requirement to ^1.33 which introduces
JsonSchemaRequestException / JsonSchemaResponseException. In ThrowableHandler,
normalise JsonSchemaRequestException into BadRequestException (code 400) so
VndError emits the correct 4xx status instead of falling through to 500.
JsonSchemaResponseException (server-side schema mismatch) is unchanged and
continues to produce a 500.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a45f48d8-aa56-4f97-b6c0-ccdb09f65ed6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 91f182ed-5c1c-4089-aecd-819ecd2b7728

📥 Commits

Reviewing files that changed from the base of the PR and between adec301 and 5d8a6a2.

📒 Files selected for processing (3)
  • composer.json
  • src/Provide/Error/ThrowableHandler.php
  • tests/Provide/Error/ThrowableHandlerTest.php

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The PR upgrades bear/resource and maps JsonSchemaRequestException to BadRequestException. Tests cover HTTP 400 request errors and HTTP 500 response errors.

Changes

JSON schema error handling

Layer / File(s) Summary
Resource dependency update
composer.json
The bear/resource constraint changes from ^1.16 to ^1.33.
Request exception mapping and tests
src/Provide/Error/ThrowableHandler.php, tests/Provide/Error/ThrowableHandlerTest.php
ThrowableHandler converts JSON schema request exceptions to bad-request exceptions. Tests verify HTTP 400 and HTTP 500 handling for request and response exceptions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5d8a6

This PR changes schema request failures to return 400 responses while preserving 500 responses for schema response failures; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: handling JsonSchemaRequestException as a 400 Bad Request.
Description check ✅ Passed The description accurately covers the dependency update, exception handling, response behavior, and added tests.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/json-schema-exception-handler

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (adec301) to head (7632ccd).
⚠️ Report is 5 commits behind head on 1.x.

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #189   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity        52        53    +1     
===========================================
  Files             18        18           
  Lines            131       125    -6     
===========================================
- Hits             131       125    -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koriym

koriym commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit 95f713b into 1.x Aug 23, 2026
33 checks passed
@koriym
koriym deleted the feature/json-schema-exception-handler branch August 23, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant